﻿using CmsBook.Models;
using Microsoft.EntityFrameworkCore;

namespace CmsBook.Contexts
{
  public class BookDbContext : DbContext
  {
    public DbSet<Book> Books { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
      string connStr = "Host=postgres;Port=5432;Database=dotnet_cms;Username=default;Password=secret;search path=public";
      optionsBuilder.UseNpgsql(connStr);
      optionsBuilder.LogTo(Console.WriteLine);
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
      base.OnModelCreating(modelBuilder);
      modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
    }
  }
}
